package model;

import java.util.ArrayList;
import java.util.List;

import model.exceptions.NoSuchLinkException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * This object will contain the different object taking part in the mapping process, namely
 * the two objects and a list of links between their respective attributes.
 * @author Corentin
 *
 */
public class Mapping {
	private final static Logger log = LoggerFactory.getLogger(Mapping.class);
	
	private JavaObject source;
	private JavaObject target;
	private List<Link<Attribute, Attribute>> links;
	
	public Mapping() {
		source = null;
		target = null;
		
	}
	
	/**
	 * Add a link between attributes to the list of links.
	 * @param link
	 */
	public void addLink(Link<Attribute,Attribute> link) {
		if (this.links == null) {
			this.links = new ArrayList<Link<Attribute,Attribute>>();
		}
		if (!this.links.contains(link)) {
			this.links.add(link);
		}
	}
	
	/**
	 * Remove a link between attributes from the list of links
	 * @param link
	 * @throws NoSuchLinkException
	 */
	public void removeLink(Link<Attribute,Attribute> link) throws NoSuchLinkException {
		if (this.links != null) {
			if (this.links.remove(link) == false) {
				throw new NoSuchLinkException();
			}
		}
	}
	
	/*
	 * Getters and setters
	 */
	public void setSource(JavaObject source) {
		this.source = source;
	}
	
	public void setTarget(JavaObject target) {
		this.target = target;
	}
	
	public JavaObject getSource() {
		return this.source;
	}
	
	public JavaObject getTarget() {
		return this.target;
	}
	
	public List<Link<Attribute, Attribute>> getLinks() {
		return this.links;
	}
	
	public void setLinks(List<Link<Attribute,Attribute>> list) {
		this.links = list;
	}
}
